package ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.devicecontroller.command;

import net.wimpi.modbus.msg.ModbusRequest;
import net.wimpi.modbus.msg.ModbusResponse;
import net.wimpi.modbus.msg.WriteCoilRequest;

public class CoilCommand extends AbstractCommand implements BitCommand{
	
	private boolean bit;

	public CoilCommand(){
		super();
	}
	
	@Override
	public boolean needRetrieve() {
		return false;
	}

	@Override
	public ModbusRequest getRetriveRequest() throws CommandException {
		throw new CommandException("CoilCommand has not retrieve request");
	}

	@Override
	public void setRetrieveResponse(ModbusResponse res) throws CommandException {
		throw new CommandException("CoilCommand can not process RetrieveResponse");
	}

	@Override
	public ModbusRequest getCommandRequest() {
		return new WriteCoilRequest(getAddress(), isBit());
	}

	/**
	 * @return the bit
	 */
	public boolean isBit() {
		return bit;
	}

	/**
	 * @param bit the bit to set
	 */
	public void setBit(boolean bit) {
		this.bit = bit;
	}
	

}
